package cn.example.vip.mall.user.controller;


import cn.example.vip.mall.user.entity.Address;
import cn.example.vip.mall.user.service.AddressService;
import cn.example.vip.mall.util.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/address")
public class AddressControllelr {
	@Autowired
	private AddressService addressService;
	@Autowired
	private HttpServletRequest request;
	
	/**
	 * 查询用户地址
	 * debug
	 */
	@GetMapping("/list")
	public RespResult<List<Address>> address() {
		// 从过滤过的请求头获取用户名
		String userName = request.getHeader("username");	//"test";
		List<Address> addressList = addressService.listByUserName(userName);
		return RespResult.ok(addressList);
	}
	
	/**
	 * 查询用户地址
	 */
	@GetMapping("/list/{userName}")
	public RespResult<List<Address>> addressByUserName(@PathVariable("userName") String userName) {
		List<Address> addressList = addressService.listByUserName(userName);
		return RespResult.ok(addressList);
	}
}
